<?php $this->load->view('includes/head.php'); ?>

<div class="container">
  <div class="row">


    <div class="col-sm-12">
     <h3>All Tasks </h3>
     <hr>
     <?php if (count($tasks) < 1 || !is_array($tasks)): ?>
       <p><a href="/tasks/add-new-task">There are no tasks created yet. Why not create one?</a> <br>
       If you have nothing to do, then perhaps you're not trying hard enough <br>
       Now, let's do some work!
       </p>
     <?php else: ?>
      <table class="table table-hover table-striped">
      <thead>
        <tr>
          <th>#</th>
          <th>Posted On:</th>
          <th>Task</th>
          <th>Owner</th>
          <th>Priority</th>
          <th>Status</th>
        </tr>
      </thead>
      <tbody>
        <?php 
        $count = 0;
        foreach ($tasks as $task) {
          $title = $task->title;
          $url = site_url('tasks/'.$task->url);
          $content = $task->content;
          $count++;
          $edit_task_url = site_url('tasks/edit/'.$task->url);

          date_default_timezone_set('GMT');
          echo '<tr>';
          echo  '<td>'.$count.'</td>';
          echo  '<td>'.mdate('%M %d, %Y',strtotime($task->date_created)).'</td>';
          echo  '<td><a href="'.$url.'">'.$title.'</a></td>';
          echo  '<td>' .$task->first_name . ' '. $task->last_name .'</td>';

          switch ($task->priority) {
            case '1':
              echo '<td>Low</td>';
              break;
            case '2':
              echo '<td>Normal</td>';
              break;
            case '3':
              echo '<td>High</td>';
              break;
          }

          switch ($task->status) {
              case '1':
                echo '<td><span class="label label-default">Not Started</span></td>';
                break;
              case '2':
                echo '<td><span class="label label-primary">In Progress</span></td>';
                break;
              case '3':
                echo '<td><span class="label label-success">Completed</span></td>';
                break;
            }
            
            echo '</tr>';
        }
      ?>
      </tbody>
    </table>
  <?php endif; ?>
    </div>


  </div>
</div>